//
//  JPRegisterVC.m
//  JPKY
//
//  Created by 周述坚 on 16/11/15.
//  Copyright © 2016年 Vitas. All rights reserved.
//

#import "JPRegisterVC.h"
#import "HMAdditions.h"
#import "InterfaceTool.h"
#import "JPDiseaseListVC.h"
#import "JPConcernDoctorVC.h"

@interface JPRegisterVC ()
@property (weak, nonatomic) IBOutlet UILabel *diseaseLable;
@property (weak, nonatomic) IBOutlet UIView *diseaselist01;
@property (weak, nonatomic) IBOutlet UIView *diseaselist02;

@property (weak, nonatomic) IBOutlet UIView *therapyMethodView;
@property (weak, nonatomic) IBOutlet UIView *showDoctorView;

/**
 *  按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *didDiagnose;
@property (weak, nonatomic) IBOutlet UIButton *noDiagnose;
@property (weak, nonatomic) IBOutlet UIButton *didTreat;
@property (weak, nonatomic) IBOutlet UIButton *noTreat;

@property (weak, nonatomic) IBOutlet UILabel *treatlabel;
@property (weak, nonatomic) IBOutlet UILabel *doctorsLabel;

@end

@implementation JPRegisterVC {
    NSInteger _select;
    
    BOOL _didD;
    BOOL _noD;
    BOOL _didT;
    BOOL _noT;
}

/**
 *  确诊按钮响应事件
 */
- (IBAction)didDiagnose:(id)sender {
    if (_select == 0) {
        [self warn];
    } else {
        if (_didD != YES ) {
            [self.didDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateNormal];
            _didD = YES;
        } else {
            [self.didDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
            _didD = NO;
        }
    }
    
    if (_noD == YES) {
        [self.noDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        _noD = NO;
    }
}

/**
 *  未确诊按钮点击事件
 */
- (IBAction)noDiagnose:(id)sender {
    if (_select == 0) {
        [self warn];
    } else {
        if (_noD != YES ) {
            [self.noDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateNormal];
            _noD = YES;
        } else {
            [self.noDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
            _noD = NO;
        }
    }
    if (_didD == YES) {
        [self.didDiagnose setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        _didD = NO;
    }
}

/**
 *  已接受治疗按钮
 */
- (IBAction)didTreat:(id)sender {
    self.treatButton.enabled = YES;
    [self.treatButton setBackgroundImage:[UIImage imageNamed:@"nav.png"] forState:UIControlStateNormal];
    if (_select == 0) {
        [self warn];
    } else {
        self.therapyMethodView.hidden = NO;
        if (_didT != YES ) {
            [self.didTreat setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateNormal];
            _didT = YES;
        } else {
            [self.didTreat setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
            self.therapyMethodView.hidden = YES;
            _didT = NO;
        }
    }
    
    if (_noT == YES) {
        [self.noTreat setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        _noT = NO;
    }
}

/**
 *  未接受治疗按钮
 */
- (IBAction)noTreat:(id)sender {
    self.treatButton.enabled = YES;
    [self.treatButton setBackgroundImage:[UIImage imageNamed:@"nav.png"] forState:UIControlStateNormal];
    
    if (_select == 0) {
        [self warn];
    } else {
        if (_noT != YES ) {
            [self.noTreat setImage:[UIImage imageNamed:@"illness_rb_img_sel.png"] forState:UIControlStateNormal];
            self.therapyMethodView.hidden = YES;
            
            _noT = YES;
        } else {
            [self.noTreat setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
            _noT = NO;
        }
    }
    
    if (_didT == YES) {
        [self.didTreat setImage:[UIImage imageNamed:@"illness_rb_img_nor.png"] forState:UIControlStateNormal];
        _didT = NO;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _select = 0;
    // 设置抬头
    self.navigationItem.title = self.titleStr;
    self.diseaseLable.text = [NSString stringWithFormat:@"疾病类型:%@",self.titleStr];
    
    // 给疾病类型添加手势手势
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSelectorUserView:)];
    [self.diseaselist01 addGestureRecognizer:tapGesture];
    
    UITapGestureRecognizer *tapGesture02 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSelectorUserView02:)];
    [self.diseaselist02 addGestureRecognizer:tapGesture02];
    
    UITapGestureRecognizer *tapGesture03 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSelectorUserView03:)];
    [self.therapyMethodView addGestureRecognizer:tapGesture03];
    
    // 设置医生数量
    [self setDoctorsNumber];
}

/**
 *  响应方法 01
 */
- (void)didSelectorUserView:(UIView *)view {
    JPDiseaseListVC *diseaseView = [JPDiseaseListVC new];
    void(^complement)() = ^(NSString *title){
        self.chooseLabel.text = title;
        self.chooseLabel.textColor = [UIColor blackColor];
        _select = 2;
        if ([title isEqualToString:@"胃恶性肿瘤"]) {
            _select = 1;
        }
    };
    // push到下一个界面
    [self.navigationController pushViewController:diseaseView animated:YES];
    diseaseView.tag = self.tag;
    diseaseView.completion = complement;
}

/**
 *  响应方法02
 */
- (void)didSelectorUserView02:(UIView *)view {
    // 1.实例化alert:alertControllerWithTitle
    if (_select == 0) {
        // 警告
        [self warn];
    } else if (_select == 1) {
        JPDiseaseListVC *diseaseView = [JPDiseaseListVC new];
        [self.navigationController pushViewController:diseaseView animated:YES];
        diseaseView.tag = 1000;
        void(^complement)() = ^(NSString *title) {
            self.titleStrLabel.text = title;
            self.titleStrLabel.textColor = [UIColor blackColor];
            _select = 2;
            if ([title isEqualToString:@"胃恶性肿瘤"]) {
                _select = 1;
            }
        };
        diseaseView.completion = complement;
        
    } else {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"该类型没有并发症" message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
    }
}

/**
 *  响应3方法 -- 点击治疗方式的方法
 */
- (void)didSelectorUserView03:(UIView *)view {
    JPDiseaseListVC *diseaseView = [JPDiseaseListVC new];
    [self.navigationController pushViewController:diseaseView animated:YES];
    diseaseView.tag = 1001;
    void(^complement)() = ^(NSString *title) {
        self.treatlabel.text = title;
        self.treatlabel.textColor = [UIColor blackColor];
        self.showDoctorView.hidden = NO;
    };
    diseaseView.completion = complement;
}

-(void)viewDidLayoutSubviews {
    // 设置背景颜色
    self.view.backgroundColor = [UIColor hm_colorWithRed:235 green:234 blue:241];
}

/**
 *  设置医生数量
 */
- (void)setDoctorsNumber {
    [[InterfaceTool sharedInterfaceTool] getDoctorCountSuccess:^(id response) {
        NSDictionary *result = response[@"data"];
        _doctorsLabel.text = [NSString stringWithFormat:@"%@位医生", result[@"doctor_count"]];
        NSLog(@"%@", _doctorsLabel.text);
    } failure:^(NSError *error) {
        NSLog(@"%@", error);
    }];
}

#pragma mark 弹出警告的方法
- (void)warn {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请先选择疾病类型" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil]];
    
    [self presentViewController:alert animated:YES completion:nil];
}

/**
 *  点击就医申请按钮响应事件
 */
- (IBAction)treatButtonAction:(id)sender {
    JPConcernDoctorVC *docVC = [JPConcernDoctorVC new];
    docVC.tag = 100;
    [self.navigationController pushViewController:docVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
